<template>
  <view class="my-login-component">
    <uni-icons type="contact-filled" size="100" color="#afafaf"></uni-icons>
    <button class="login-button" open-type="getUserInfo" @getuserinfo="getuserinfo">
      一键登录
    </button>
    <text>登录后尽享更多权益</text>
  </view>
</template>

<script>
  import { mapActions, mapState } from 'vuex'
  export default {
    name:"MyLogin",
    data() {
      return {
        
      };
    },
    computed: {
      ...mapState('user', ['redirectInfo'])
    },
    methods: {
      getuserinfo(e) {
        this.updateUserInfo(e.detail.userInfo)
        this.getToken(e.detail)
      },
      async getToken(detail) {
        const { encryptedData, iv, rawData, signature } = detail
        const loginList = await uni.login()
        if(loginList[0] === null && loginList[1].errMsg === 'login:ok') {
          const { code } = loginList[1]
          const queryObj = {
            code, encryptedData, iv, rawData, signature
          }
          // 注：token假数据
          const token = 'fake data'
          this.updateToken(token)
          if(this.redirectInfo.openType === 'switchTab') {
            uni.switchTab({
              url: this.redirectInfo.url
            })
          }
        }
      },
      ...mapActions('user', ['updateUserInfo', 'updateToken'])
    }
  }
</script>

<style lang="scss" scoped>
.my-login-component {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 200rpx;
  height: 750rpx;
  background-color: #f8f8f8;
  overflow: hidden;
  .login-button {
    margin: 40rpx 0;
    height: 100rpx;
    width: 80%;
    background-color: #c00000;
    border-radius: 50rpx;
    color: white;
    font-size: 40rpx;
    text-align: center;
    line-height: 100rpx;
  }
  text {
    color: gray;
    font-size: 28rpx;
  }
  &::after {
    content: '';
    position: absolute;
    bottom: 0;
    transform: translateY(50%);
    height: 50rpx;
    width: 750rpx;
    background-color: white;
    border-radius: 100%;
  }
}
</style>